<center>
    <div class="container"  style="width: 80%;">
        <h2><?php echo USER; ?>的主页</h2>
        <a class="btn btn-primary" href="index.php?controller=Task&action=index">任务主页</a>
        <a class="btn btn-primary" href="index.php?controller=Users&action=logout">注销</a>
        <p>用户任务列表<br/>未完成</p>

        <table class="table table-dark table-hover">
            <thead>
            <tr style="text-align: center;">
                <th>标题</th>
                <th>发布人</th>
                <th>任务详情</th>
                <th>完成状态</th>
                <th>完成任务</th>
                <th>放弃任务</th>
            </tr>
            </thead>
            <tbody>
                <?php foreach ($data[0] as $value) { if($value['principal'] == USER && $value['status'] == 0) {?>
                <tr style="text-align: center;">
                    <td>
                        <?php echo $value['title']; ?>
                    </td>
                    <td>
                        <?php echo $value['leader']; ?>
                    </td>
                    <td>
                        <?php echo $value['task_info']; ?>
                    </td>
                    <td>
                        <?php echo $value['status'] ? '已完成' : '未完成'; ?>
                    </td>
                    <td style="padding-top: 4px;padding-bottom: 4px;">
                        <form action="index.php?controller=Task&action=finishTask" method="post" style="margin-bottom: 0px;">
                            <input name="title" type="text" value="<?php echo $value['title']; ?>" hidden />
                            <center><button type="submit" class="btn btn-primary">完成任务</button></center>
                        </form>
                    </td>
                    <td style="padding-top: 4px;padding-bottom: 4px;">
                        <form action="index.php?controller=Task&action=giveUpTask" method="post" style="margin-bottom: 0px;">
                            <input name="title" type="text" value="<?php echo $value['title']; ?>" hidden />
                            <center><button type="submit" class="btn btn-primary">放弃任务</button></center>
                        </form>
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>

        <p>已完成</p>
        <table class="table table-dark table-hover" style="max-width: 80%;">
            <thead>
            <tr style="text-align: center;">
                <th>标题</th>
                <th>发布人</th>
                <th>任务详情</th>
                <th>完成状态</th>
            </tr>
            </thead>
            <tbody>
                <?php foreach ($data[0] as $value) { if($value['principal'] == USER && $value['status'] == 1) {?>
                <tr style="text-align: center;">
                    <td>
                        <?php echo $value['title']; ?>
                    </td>
                    <td>
                        <?php echo $value['leader']; ?>
                    </td>
                    <td>
                        <?php echo $value['task_info']; ?>
                    </td>
                    <td>
                        <?php echo $value['status'] ? '已完成' : '未完成'; ?>
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>

        <p>发布的任务</p>
        <table class="table table-dark table-hover">
            <thead>
            <tr style="text-align: center;">
                <th>标题</th>
                <th>发布人</th>
                <th>负责人</th>
                <th>任务详情</th>
                <th>完成状态</th>
                <th>删除任务</th>
            </tr>
            </thead>
            <tbody>
                <?php foreach ($data[0] as $value) { if($value['leader'] == USER) {?>
                <tr style="text-align: center;">
                    <td>
                        <?php echo $value['title']; ?>
                    </td>
                    <td>
                        <?php echo $value['leader']; ?>
                    </td>
                    <td>
                        <?php echo $value['principal']; ?>
                    </td>
                    <td>
                        <?php echo $value['task_info']; ?>
                    </td>
                    <td>
                        <?php echo $value['status'] ? '已完成' : '未完成'; ?>
                    </td>
                    <td style="padding-top: 4px;padding-bottom: 4px;">
                        <form action="index.php?controller=Task&action=deleteTask" method="post" style="margin-bottom: 0px;">
                            <input name="title" type="text" value="<?php echo $value['title']; ?>" hidden />
                            <center><button type="submit" class="btn btn-primary">删除任务</button></center>
                        </form>
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>

        <p>任务完成比重</p>
        <table class="table table-dark table-hover" style="max-width: 40%;">
            <thead>
            <tr style="text-align: center;">
                <th>参与者</th>
                <th>任务完成比重</th>
            </tr>
            </thead>
            <tbody>
                <?php foreach ($data[1] as $key => $value) { if($key != null) { ?>
                <tr style="text-align: center;">
                    <td>
                        <?php echo $key; ?>
                    </td>
                    <td>
                        <?php echo $value * 100 . '%'; ?>
                    </td>
                </tr>
                <?php } } ?>
                <tr style="text-align: center;">
                    <td>
                        已完成
                    </td>
                    <td>
                        <?php if(isset($data[1][null])) { echo $data[1][null] * 100 . '%'; } else { echo '0%'; } ?>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</center>